home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / dev / misc / BoulderEngine.lha / BOULDER_Mar_18.lha / BOULDER.C next >
Encoding:
C/C++ Source or Header  |  1995-03-19  |  8.8 KB  |  345 lines

  1. /* =============(BOULDER.C)=========================================
  2.    =  BOULDER DASH 2 MAIN BODY. ©1993-5 by SAVELSOFTWARE inc.      =
  3.    =  Idea: Peter Liepa., C coding: Levas Vabolis.                 =
  4.    =  (In Fact real BOULDER DASH is © by First Star Soft. )        =
  5.    ================================================================= */
  6. #include "BOULDER0.C" /* graphics */
  7. #include "BOULDER3.C" /* man */
  8. #include "LEVELS.C"   /* Lygiai */
  9. #include "ROTATE.C"   /* color cycle */
  10. /* #include "music.c"*/ /* Sound routines V1.0 or higher */
  11. STATIC UBYTE bummx[50],bummy[50],bummi[50],Adz,Adb,GREITIS;
  12. STATIC USHORT BUMPOINT,clos,fillalready,oldclos,levl,MAXLEVL;
  13. STATIC ULONG HSCORE;
  14. SHORT NextLevel();
  15. titrai()
  16. {
  17. SetAPen(&rastport,5L); RectFill(&rastport,63L,0L,799L,11L);
  18. PrntI(70,1,16); PrntI(80,1,18); PrntI(130,1,10); PrntI(140,1,11);
  19. PrntI(150,1,12); PrntI(160,1,13); PrntI(170,1,5); PrntI(180,1,18);
  20. PrntI(230,1,5); PrntI(240,1,14); PrntI(250,1,0); PrntI(260,1,15);
  21. PrntI(270,1,13); PrntI(280,1,18); PrntI(360,1,17); PrntI(370,1,11);
  22. PrntI(380,1,5); PrntI(390,1,14); PrntI(400,1,0); PrntI(410,1,15);
  23. PrntI(420,1,13); PrntI(430,1,18); PrntL(440,1,HSCORE);
  24. PrntI(510,1,11); PrntI(520,1,16); PrntI(530,1,18);
  25. Prnt(540,1,ITEMS);  PrntI(580,1,14); PrntI(590,1,12); PrntI(600,1,18);
  26. Prnt(610,1,levl); Prnt(190,1,LIVES); PrntL(290,1,SCORE); Prnt(90,1,0);
  27. }
  28. main()
  29. {
  30.  MAXLEVL=maximum();
  31.  levl=0; GREITIS=4; HSCORE=10000;
  32.  pasiruosk(); WaitTOF(); AudioON();
  33.  scena(&rastport); Makegraphics(); titrai();
  34.  PrntI(70,1,10); Prnt(90,1,GREITIS);
  35.  while(pekb(0xBFEC00)!=117)
  36.  {
  37.    scrolll(0);
  38.    rotate();
  39.    if(man2())
  40.    {
  41.     if(levl>0 && hx==-1) { levl--; }
  42.     if(levl<MAXLEVL && hx==1) {levl++; }
  43.     Prnt(610,1,levl); Delay(7); rotate(); Delay(6); rotate();
  44.     if(GREITIS>0 && hy==-1) {GREITIS--; }
  45.     if(GREITIS<8 && hy==1) {GREITIS++; }
  46.     PrntI(70,1,10); Prnt(90,1,GREITIS);
  47.    }
  48.    if(fire())
  49.    {
  50.     LIVES=2;
  51.     Play(); Audiopirst2(0); scena(&rastport); Makegraphics(); titrai();
  52.     PrntI(70,1,10); Prnt(90,1,GREITIS);
  53.    }
  54.    Delay(1);
  55.  }
  56. AudioOFF(); for(levl=0;levl<126;levl++) {rotate(); }
  57. Delay(2);
  58. FMemory(); exit();
  59. } /* End of Main */
  60. Play()
  61. {
  62. SHORT n,x,y,i,j,l;
  63. BUMPOINT=0; FINISH=0;
  64. level(levl); SCORE=0;
  65. SetRast(&rastport,0L); Makegraphics();
  66. show();
  67. titrai(); ALIVE=15;
  68. fillalready=0; oldclos=0;
  69. for(n=TIM;n>0;n--) {   ALIVE--; for(l=0;l<GREITIS;l++) {WaitTOF();}
  70.   bumm2();
  71.   for(x=0;x<29;x++) {
  72.    for(y=24;y>=0;y--) { j++;
  73.      if(Adz && j<70) { --Adz; Audiodzin2(Adz);}
  74.      if(Adb && j>70 && j<140){ --Adb; Audiopirst2(Adb);}
  75.                     
  76.     if (k(x,y)<9)
  77.        analize(x,y);
  78.     else { k(x,y)=k(x,y)/10; }
  79.    } /* NEXT Y */
  80.   }  /* NEXT X */
  81.   j=0;
  82.   if(Adzin) {Audiodzin(); Adz=64; Adzin=0;}
  83.   if(Abum) {Audiopirst(); Abum=0; Adb=64; }
  84.   if(!oldclos) { fillalready=1; }
  85.   if(oldclos>HMAGMA && !fillalready) { ffill(); }
  86.   if(!clos && !fillalready) { ffill(); }
  87.   oldclos=0; clos=0;
  88.   if(!ALIVE) { if(LIVES>0) {LIVES--; ALIVE=15; Death(); n=TIM; } }
  89.   Prnt(90,1,n/10); PrntL(290,1,SCORE);
  90.   Prnt(540,1,ITEMS);
  91.   if(!LIVES && !ALIVE) { n=0; }
  92.   i=pekb(0xbfec00);
  93.   if(i==117 || n<2)           /* ESC klavisas */
  94.    {
  95.     n=0;
  96.     if(LIVES>0)
  97.      {
  98.       WaitTOF(); LIVES--; n=TIM; Prnt(190,1,LIVES);
  99.       Death();
  100.      }
  101.    }
  102.   if(FINISH){ LIVES++; n=NextLevel(n); oldclos=0; fillalready=0; }
  103.   rotate();
  104. }    /* NEXT N */
  105.  
  106. Delay(5);
  107. hide();
  108. Delay(50);
  109.  
  110. } /* End of Play */
  111.  
  112. SHORT NextLevel(m)
  113. SHORT m;
  114. {
  115. SHORT i,n=0;
  116.  Audiodzin();
  117.  for(i=m;i>0;i-=20) {
  118.      SCORE+=10; PrntL(290,1,SCORE);
  119.      rotate();
  120.      if(n)
  121.       Audiopip(10);
  122.      else
  123.       {Audiodzin2(10); }
  124.        n=!n;
  125.                     } Audiodzin2(0);
  126.  if(SCORE>HSCORE) {HSCORE=SCORE; PrntL(440,1,HSCORE);}
  127.  levl++; if(levl>MAXLEVL) {levl=0;}
  128.  Delay(50); hide(); level(levl); show(); titrai(); Delay(10);
  129.  FINISH=0; return(TIM);
  130. } /* end of n=NextLevel(n) */
  131. Death()
  132. {
  133.   Audiopirst2(0); Delay(60); hide(); level(levl); show(); titrai();
  134.   fillalready=0; oldclos=0;
  135. }
  136. ffill()
  137. {
  138. SHORT x,y,fff=3;
  139.  
  140. fillalready=1;
  141. if(oldclos>CRISTAL) {fff=2;}
  142. for(x=1;x<30;x++)
  143.  {
  144.   for(y=1;y<12;y++)
  145.    {
  146.     if(e(x,y)==6) {set(x,y,fff); }
  147.    }
  148.  }
  149. }
  150. analize(x,y)  /* <<<<<<<<< Pati rimciausia paprograme >>>>>>>>>>>>> */
  151. SHORT x,y;
  152. {
  153. LONG kq,jj;
  154. SHORT q,c1,c2,c3,c4,p,kz,i,j,bb,zz,uzz,manhere,os;
  155. SHORT ez[5];
  156. q=e(x,y);
  157. if (q==10) { man(x,y); ALIVE++; return; }
  158. if(q==9 && !ITEMS) {set(x,y,0); WaitTOF(); set(x,y,11);
  159.   WaitTOF(); WaitTOF(); set(x,y,9); e(x,y)=12; }
  160. if(q<2) { return; }
  161. if(q==7) {return; }
  162. c1=x+1; c2=x-1; c3=y-1; c4=y+1;
  163. p=e(x,c4);
  164. if (q==14 && k(x,y)==2){bumm(x,c3,0); detonate(x,c3);return;}
  165. if (q==2 || q==3)
  166.  {
  167.   if (p==0) { set(x,c4,q); set(x,y,0); k(x,c4)=1; return; }
  168.   if (k(x,y)>0) { /* kinetinis sokas */
  169.     if(p==4 || p==10 || p==14) { bumm(x,y,0); }
  170.     if(p==14){detonate(x,y); }
  171.     if(p==5) { bumm(x,y,3); Adzin=1;}
  172.                 }
  173.   if (p==2 || p==3 || p==8 || p==14) {
  174.    if(!e(c2,y) && !e(c2,c4))
  175.     { set(c2,y,q); set(x,y,0); k(c2,y)=0; if(p==5){Adzin=1;} return;}
  176.    if(!e(c1,y) && !e(c1,c4))
  177.     { set(c1,y,q); set(x,y,0); k(c1,y)=9; if(p==5){Adzin=1;} return;}
  178.   }
  179.   if(q==3 && k(x,y)!=0) {Adzin=1;}
  180.   k(x,y)=0;
  181.   return;
  182.  }
  183. bb=0; manhere=0; uzz=1; ez[0]=7; ez[5]=7;
  184. ez[1]=e(c1,y); ez[2]=e(x,c3); ez[3]=e(c2,y);
  185. ez[4]=e(x,c4);
  186. if(k(x,c3)==1) {ez[2]=6;}
  187.  for(i=1; i<=5; i++)
  188.  {
  189.   if (ez[i]==6) {bb=1;}
  190.   if (ez[i]==10) { manhere=1; }
  191.   if (!ez[i]) {uzz=0;}
  192.  }
  193. if (manhere) {bb=1;}
  194. /* if (uzz && !manhere) {return; } */
  195. if (q==4) {
  196.     if (bb) { bumm(x,c3,0); return; }
  197.     jj=4L; zz=0; ;kz=0; if(k(x,y)>1) {kz=k(x,y)-1;}
  198.     while (jj>0L && !zz)
  199.     { kq=jj+kz-3L;
  200.       if (kq>4) {kq-=4;}
  201.       if (kq<1) {kq+=4;}
  202.       if(!ez[kq]) { zz=1; go(c1,c2,c3,c4,kq,q,x,y); }
  203.       jj--;
  204.     }  return;
  205.  }
  206. if (q==5) {
  207.    if (bb) {bumm(x,c3,3); return; }
  208.    jj=1L; zz=0; kz=0;
  209.   if (k(x,y)>1) { kz=k(x,y)-1; }
  210.   while (jj<5L && !zz)
  211.   { kq=jj+kz-2L;
  212.    if (kq>4) {kq-=4; }
  213.    if (kq<1) {kq+=4; }
  214.    if (!ez[kq]) {zz=1; go(c1,c2,c3,c4,kq,q,x,y); }
  215.    jj++;
  216.   } return;
  217. }
  218. if(q==6) {
  219.   os=0;
  220.   for(i=1;i<5;i++) {
  221.     if (ez[i]<2) { os=1; j=i; }
  222.    }
  223.   clos+=os; oldclos++;
  224.   if (os && (!ez[j] || ez[j])) {
  225.     if( galima(21) )
  226.       { mgo(j,x,y,c1,c2,c3,c4); }
  227.    }
  228.  }
  229. if(q==15) /* Judanti Siena */
  230.  {
  231.   if(!e(c2,y)) {set(c2,y,15); return;}
  232.   if(!e(c1,y)) {set(c1,y,15); k(c1,y)=9; return;}
  233.  }
  234. if(q==16) /* Neauganti magma */
  235.  {
  236.   if(!e(x,c4)) { q=e(x,c3); if(q==2 || q==3)
  237.   { if(galima(11)) { set(x,c4,q); set(x,c3,0); } } }
  238.   return;
  239.  }
  240. j=e(x,c4);
  241. if(q==17) /* Dzin-Dzin Siena */
  242.  {
  243.   q=e(x,c3); if(k(x,c3)==1)
  244.   {
  245.    if(q==2) {set(x,c3,0); if(!j){set(x,c4,3); Adzin=1; }}
  246.    if(q==3) {set(x,c3,0); if(!j){set(x,c4,2); Adzin=1; }}
  247.   } return;
  248.  }
  249. if(q==18) /* Akmenu generatorius */
  250.  { if(!j) {set(x,c4,2); } }
  251. if(q==19) /* Bril. generatorius */
  252.  { if(!j) {set(x,c4,3); } }
  253. if(q==21) { if(k(x,c3)==1) {sprogmina(c1,c2,c3,y); }return; } /* mina */
  254. if(q==23) {BigSuck(x,y,c2,c3);
  255.            } /* Juodoji skyle, SUCK EVERYTHING! */
  256. if(q==14) {
  257.       p=e(x,c4); if(k(x,y)==0){
  258.       if(p==0){set(x,y,0); set(x,c4,14);
  259.                 k(x,c4)=1; return;}
  260.       if(p==2 || p==3 || p==8 || p==q) {
  261.                      if(!e(c2,y) && !e(c2,c4))
  262.                                  {set(c2,y,q); set(x,y,0); return; }
  263.                      if(!e(c1,y) && !e(c1,c4))
  264.                                  {set(c1,y,q); set(x,y,0); return; }
  265.         } /* if p=2,3,8,14 */
  266.                             return; }/* if K */
  267.            if(p==0){set(x,y,0); set(x,c4,14); k(x,c4)=1; return;}
  268.            bumm(x,c3,0); detonate(x,c3); }  /* BOMBA */
  269. return;
  270. }
  271. BigSuck(x,y,c2,c3) /* Juod. skyles siurblys */
  272. SHORT x,y,c2,c3;
  273. {
  274. SHORT i,j;
  275.  for(i=c2;i<x+2;i++) {
  276.    for(j=c3;j<y+2;j++) {
  277.       if(e(i,j)!=7 && e(i,j)!=23 && e(i,j)!=8) {set(i,j,0); }
  278.    }
  279.  }
  280. }
  281. sprogmina(c1,c2,c3,c4) /* Didelis sprogimas */
  282. SHORT c1,c2,c3,c4;
  283. {
  284.  if(e(c2,c3-1)!=7){bumm(c2,c3-1,0);}
  285.  if(e(c1,c3-1)!=7){bumm(c1,c3-1,0);}
  286.  if(e(c2,c4)!=7){bumm(c2,c4,0);}
  287.  if(e(c1,c4)!=7){bumm(c1,c4,0);}
  288. }
  289. bumm(x,y,i)
  290. SHORT x,y,i;
  291. {
  292.  SHORT j,z;
  293.  BUMPOINT++; bummi[BUMPOINT]=i; bummx[BUMPOINT]=x;
  294.  bummy[BUMPOINT]=y;  Abum=1;
  295.  for(j=x-1;j<x+2;j++)
  296.  {
  297.   for(z=y;z<y+3;z++)
  298.   {
  299.    if (e(j,z)!=7) {set(j,z,11); }
  300.   }
  301.  }
  302. }
  303. bumm2()
  304. {
  305. SHORT n;
  306. for(n=1;n<=BUMPOINT;n++) { b2(n); }
  307. BUMPOINT=0; }
  308.  
  309. b2(n)
  310. SHORT n;
  311. {
  312. SHORT x,y,i,j,z;
  313.  x=bummx[n]; y=bummy[n]; i=bummi[n];
  314.  WaitTOF();
  315.  for(j=x-1;j<x+2;j++)
  316.   {
  317.    for(z=y;z<y+3;z++)
  318.     {
  319.      if (ek[z*30+j]!=7) {set(j,z,i); }
  320.     }
  321.   }
  322. }
  323. detonate(x,y) /* Aplinkiniu bombu detonavimas */
  324. SHORT x,y;
  325. {
  326. SHORT i,y2,x2;
  327.  if(x<2){x=2;}
  328.  if(x>27){x=27;}
  329.  if(y<2){y=2;}
  330.  if(y>24){y=10;}
  331.  y2=y-2; x2=y+3;
  332.  for(i=x-2;i<x+3;i++) { if(e(i,y2)==14){
  333.                               k(i,y2)=20; }
  334.                         if(e(i,x2)==14){
  335.                               k(i,x2)=20; }
  336.                       }
  337.  y2=x-2; x2=x+2;
  338.  for(i=y-1;i<y+2;i++) { if(e(y2,i)==14){
  339.                               k(y2,i)=20; }
  340.                         if(e(x2,i)==14){
  341.                               k(x2,i)=20; }
  342.                       }
  343. }
  344.  
  345.